package com.sevenGroup.pawnshop.controller;


import com.sevenGroup.pawnshop.Utils.Result;
import com.sevenGroup.pawnshop.controller.form.AuthenticateForm;
import com.sevenGroup.pawnshop.controller.form.AuthenticateSelectConditionalForm;
import com.sevenGroup.pawnshop.controller.info.AuthenticateInfo;
import com.sevenGroup.pawnshop.model.Authenticate;
import com.sevenGroup.pawnshop.service.AuthenticateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sevenGroup
 * @since 2022-02-16
 */
@RestController
@RequestMapping("/authenticate")
@Api(tags = "鉴定相关：新增查询鉴定等")
public class AuthenticateController {
    @Resource
    private AuthenticateService authenticateService;

//  新增鉴定
    @ApiOperation("新增鉴定")
    @PostMapping("addAuthenticate")
    @PreAuthorize("hasAnyAuthority('boss','shopManage','worker')")
    public Result addAuthenticate(@RequestBody @ApiParam("鉴定对象") AuthenticateForm authenticateForm){
        Integer integer=authenticateService.addAuthenticate(authenticateForm);
        return Result.success(integer);
    }

    @ApiOperation("查询鉴定")
//  查询鉴定集合
    @PostMapping("selectAuthenticate")
    @PreAuthorize("hasAnyAuthority('boss','shopManage','worker')")
    public Result selectAuthenticate(@RequestBody @ApiParam("查询条件") AuthenticateSelectConditionalForm conditionalForm){
        List<AuthenticateInfo> authenticateInfos=authenticateService.selectAuthenticate(conditionalForm);
        return Result.success(authenticateInfos);
    }

    @ApiOperation("删除鉴定")
//  删除鉴定,未完善
    @PostMapping("delete")
    @PreAuthorize("hasAnyAuthority('boss','shopManage','worker')")
    public Result deleteAuthenticateById(@ApiParam("鉴定表ID")Integer id){
        Integer num=authenticateService.deleteAuthenticateById(id);
        return Result.success(num);
    }

}

